package team.jaman.autosell.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import team.jaman.autosell.dao.LoggerMapper;
import team.jaman.autosell.entity.Logger;
import team.jaman.autosell.entity.LoggerExample;
import team.jaman.autosell.service.LoggerService;
import team.jaman.autosell.tools.CommonData;
import team.jaman.autosell.tools.PageData;
@Service
public class LoggerServiceImpl implements LoggerService {
	// 注入一个LoggerMapper
	@Autowired
	private LoggerMapper loggerMapper;
	
	PageData<Logger> pageData;
	
	
	/**
	 * 增加日志
	 */
	public CommonData addLogger(Logger record) {
		CommonData commonData = new CommonData();
		
		int n = loggerMapper.insert(record);
		
		if (n>0) {
			commonData.setMsg("添加成功");
		}else {
			commonData.setMsg("添加失败");
		}
		return commonData;
	}
	/**
	 * 查询日志
	 */
	public PageData<Logger> selectLogger(int page, int limit, String keyword) {
		
		// pageHelper分页插件
		Page<Logger> startPage = PageHelper.startPage(page, limit);
		// 模糊查询数据
		List<Logger> data = loggerMapper.selectLoggerByKeyword(keyword);
		// 总记录数
		long total = startPage.getTotal();
				
		PageData<Logger> pageData = new PageData<Logger>(data, (int) total, limit, page);
		pageData.setCode(0);
		pageData.setMsg("");
		return pageData;
	}
	/**
	 * 修改日志
	 */
	public CommonData updateByPrimaryKeySelective(Logger record) {
		CommonData commonData = new CommonData();
		
		int n = loggerMapper.updateByPrimaryKeySelective(record);

		if (n>0) {
			commonData.setMsg("修改成功");
		}else {
			commonData.setMsg("修改失败");
		}
		return commonData;
	}
}
